<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>后台管理页面</title>
    <link rel="icon" th:href="@{/user/favicon.ico}" type="image/ico">
    <link th:href="@{/user/css/bootstrap.min.css}" rel="stylesheet">
    <link th:href="@{/user/css/materialdesignicons.min.css}" rel="stylesheet">
    <link th:href="@{/user/css/style.min.css}" rel="stylesheet">
</head>

<body>
<!--<script th:src="'https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js'"></script>-->
<!--<script th:src="'https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js'"></script>-->
<script th:src="@{/user/js/jquery.min.js}"></script>
<script th:src="@{/user/js/bootstrap.min.js}"></script>
<script th:src="@{/user/js/perfect-scrollbar.min.js}"></script>
<script th:src="@{/user/js/main.min.js}"></script>
<script th:src="@{/user/js/Chart.js}"></script>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <aside class="lyear-layout-sidebar">

            <!-- logo -->
            <div id="logo" class="sidebar-header">
                <a href="javascript:void(0)">
                    <img th:src="@{/user/images/logo-sidebar.png}" title="LightYear" alt="LightYear" />
                </a>
            </div>
            <div class="lyear-layout-sidebar-scroll">

                <nav class="sidebar-main">
                    <ul class="nav nav-drawer">
                        <li class="nav-item active"><a th:href="@{/go/toUserMain}"><i class="mdi mdi-home"></i> 主界面 </a></li>
                        <li class="nav-item nav-item-has-subnav" th:if="${#request.getSession().getAttribute('userId')=='admin'}">
                            <a th:href="@{/go/toPictureManagement}"><i class="mdi mdi-format-align-justify"></i> 图片管理</a>
                        </li>
                    </ul>
                </nav>
            </div>

        </aside>
        <!--End 左侧导航-->

        <!--头部信息-->
        <header class="lyear-layout-header">

            <nav class="navbar navbar-default">
                <div class="topbar">

                    <div class="topbar-left">
                        <div class="lyear-aside-toggler">
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                        </div>
                        <span class="navbar-page-title"> 后台首页 </span>
                    </div>

                    <ul class="topbar-right">
                        <!--切换主题配色-->
                        <li class="dropdown dropdown-skin">
                            <span data-toggle="dropdown" class="icon-palette"><i class="mdi mdi-palette"></i></span>
                            <ul class="dropdown-menu dropdown-menu-right" data-stopPropagation="true">
                                <li class="drop-title"><p>主题</p></li>
                                <li class="drop-skin-li clearfix">
                  <span class="inverse">
                    <input type="radio" name="site_theme" value="default" id="site_theme_1" checked>
                    <label for="site_theme_1"></label>
                  </span>
                                    <span>
                    <input type="radio" name="site_theme" value="dark" id="site_theme_2">
                    <label for="site_theme_2"></label>
                  </span>
                                    <span>
                    <input type="radio" name="site_theme" value="translucent" id="site_theme_3">
                    <label for="site_theme_3"></label>
                  </span>
                                </li>
                                <li class="drop-title"><p>LOGO</p></li>
                                <li class="drop-skin-li clearfix">
                  <span class="inverse">
                    <input type="radio" name="logo_bg" value="default" id="logo_bg_1" checked>
                    <label for="logo_bg_1"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_2" id="logo_bg_2">
                    <label for="logo_bg_2"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_3" id="logo_bg_3">
                    <label for="logo_bg_3"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_4" id="logo_bg_4">
                    <label for="logo_bg_4"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_5" id="logo_bg_5">
                    <label for="logo_bg_5"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_6" id="logo_bg_6">
                    <label for="logo_bg_6"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_7" id="logo_bg_7">
                    <label for="logo_bg_7"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_8" id="logo_bg_8">
                    <label for="logo_bg_8"></label>
                  </span>
                                </li>
                                <li class="drop-title"><p>头部</p></li>
                                <li class="drop-skin-li clearfix">
                  <span class="inverse">
                    <input type="radio" name="header_bg" value="default" id="header_bg_1" checked>
                    <label for="header_bg_1"></label>
                  </span>
                                    <span>
                    <input type="radio" name="header_bg" value="color_2" id="header_bg_2">
                    <label for="header_bg_2"></label>
                  </span>
                                    <span>
                    <input type="radio" name="header_bg" value="color_3" id="header_bg_3">
                    <label for="header_bg_3"></label>
                  </span>
                                    <span>
                    <input type="radio" name="header_bg" value="color_4" id="header_bg_4">
                    <label for="header_bg_4"></label>
                  </span>
                                    <span>
                    <input type="radio" name="header_bg" value="color_5" id="header_bg_5">
                    <label for="header_bg_5"></label>
                  </span>
                                    <span>
                    <input type="radio" name="header_bg" value="color_6" id="header_bg_6">
                    <label for="header_bg_6"></label>
                  </span>
                                    <span>
                    <input type="radio" name="header_bg" value="color_7" id="header_bg_7">
                    <label for="header_bg_7"></label>
                  </span>
                                    <span>
                    <input type="radio" name="header_bg" value="color_8" id="header_bg_8">
                    <label for="header_bg_8"></label>
                  </span>
                                </li>
                                <li class="drop-title"><p>侧边栏</p></li>
                                <li class="drop-skin-li clearfix">
                  <span class="inverse">
                    <input type="radio" name="sidebar_bg" value="default" id="sidebar_bg_1" checked>
                    <label for="sidebar_bg_1"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_2" id="sidebar_bg_2">
                    <label for="sidebar_bg_2"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_3" id="sidebar_bg_3">
                    <label for="sidebar_bg_3"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_4" id="sidebar_bg_4">
                    <label for="sidebar_bg_4"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_5" id="sidebar_bg_5">
                    <label for="sidebar_bg_5"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_6" id="sidebar_bg_6">
                    <label for="sidebar_bg_6"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_7" id="sidebar_bg_7">
                    <label for="sidebar_bg_7"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_8" id="sidebar_bg_8">
                    <label for="sidebar_bg_8"></label>
                  </span>
                                </li>
                            </ul>
                        </li>
                        <!--切换主题配色-->
                    </ul>

                </div>
            </nav>

        </header>
        <!--End 头部信息-->

        <!--页面主要内容-->
        <main class="lyear-layout-content">
            <!--模态框-->
            <div class="modal fade" tabindex="-1" role="dialog" id="myModal">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title">提示</h4>
                        </div>
                        <div class="modal-body">
                            <p>是否删除</p>
                        </div>
                        <form th:action="@{/file/fileDelete}" method="post">
                        <div class="form-group">
                            <input type="hidden" class="form-control" th:value="${path}" name="path">
                            <input type="hidden" class="form-control" name="name" id="name">
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                            <button type="submit" class="btn btn-primary">确定</button>
                        </div>
                        </form>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal-dialog -->
            </div><!-- /.modal -->
            <!--模态框2-->
            <div class="modal fade" tabindex="-1" role="dialog" id="newFolder">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title">提示:文件夹名字不能含有"."," ","/","\"</h4>
                        </div>
                        <form th:action="@{/file/NewFolder}" method="post">
                        <div class="modal-body">
                                <div class="form-group">
                                    <input type="hidden" class="form-control" id="path" th:value="${path}" name="path">
                                    <input type="text" class="form-control" id="newFolderName" name="newFolderName" onkeyup="this.value=this.value.replace(/[. /\\]/g,'')"
                                           onafterpaste="this.value=this.value.replace(/[. /\\]/g,'')" required>
                                </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                            <button type="submit" class="btn btn-primary">确定</button>
                        </div>
                        </form>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal-dialog -->
            </div><!-- /.modal -->
            <!--模态框2-->
            <div class="modal fade" tabindex="-1" role="dialog" id="fileUpload">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title">提示:文件夹名字不能含有".",并且不能在同一目录下重名</h4>
                        </div>
                        <form th:action="@{/file/upload}" method="post" enctype="multipart/form-data">
                            <div class="modal-body">
                                <div class="form-group">
                                    <input type="hidden" class="form-control" th:value="${path}" name="path">
                                    <input type="file" class="form-control" name="file" required>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                <button type="submit" class="btn btn-primary">确定</button>
                            </div>
                        </form>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal-dialog -->
            </div><!-- /.modal -->
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header">
                                <ol class="breadcrumb" th:if="${#request.getSession().getAttribute('userId')!='admin'}">
                                    <li th:each="navigation,navigationStat:${navigationArr}" th:if="(not ${navigationStat.last}) and (not ${navigationStat.first})">
                                        <a th:href="'javascript:navigation_path('+${navigationStat.index}+');'" th:text="${navigation}"></a>
                                        <input type="hidden" th:id="'navigation'+${navigationStat.index}" th:value="${navigation}">
                                    </li>
                                    <li class="active" th:each="navigation,navigationStat:${navigationArr}" th:if="${navigationStat.last}" th:text="${navigation}"></li>
                                </ol>
                                <ol class="breadcrumb" th:if="${#request.getSession().getAttribute('userId')=='admin'}">
                                    <li th:each="navigation,navigationStat:${navigationArr}" th:if="${navigationStat.first}">
                                        <a th:href="'javascript:enter_path(\''+'/'+'\');'" th:text="Home"></a>
                                    </li>
                                    <li th:each="navigation,navigationStat:${navigationArr}" th:if="(not ${navigationStat.last}) and (not ${navigationStat.first})">
                                        <a th:href="'javascript:navigation_path('+${navigationStat.index}+');'" th:text="${navigation}"></a>
                                        <input type="hidden" th:id="'navigation'+${navigationStat.index}" th:value="${navigation}">
                                    </li>
                                    <li class="active" th:each="navigation,navigationStat:${navigationArr}" th:if="${navigationStat.last}" th:text="${navigation}"></li>
                                </ol>
                            </div>
                            <div class="card-body">
                                <div class="progress progress-lg" th:if="${#request.getSession().getAttribute('userId')!='admin'}">
                                    <div class="progress-bar progress-bar-dark" role="progressbar" th:aria-valuenow="${percentage}" aria-valuemin="0" aria-valuemax="100" th:style="'min-width:5em;width:'+${percentage}+'%;'">
                                        [[${percentage}]]%;总容量30M;已用[[${size}]]M
                                    </div>
                                </div>
                                <div class="table-responsive">
                                    <input type="hidden" th:value="${path}" th:id="filepath">
                                    <a class="btn btn-primary" href="#newFolder" data-toggle="modal">新建文件夹</a>
                                    <a class="btn btn-primary" href="#fileUpload" data-toggle="modal">上传文件</a>
                                    <table class="table table-hover">
                                        <thead>
                                        <tr>
                                            <td style="text-align:center">文件</td>
                                            <td style="text-align:center">操作</td>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr th:each="file:${fileList}">
                                            <td style="text-align:center" th:text="${file}"></td>
                                            <td style="text-align:center">
                                                <a th:if="not ${file.toString().contains('.')}" th:href="'javascript:enter_path(\''+${path}+'/'+${file.toString()}+'\');'">进入 |</a>
                                                <a th:if="${file.toString().contains('.')}" th:href="'javascript:download(\''+${file.toString()}+'\');'">下载 |</a>
                                                <a href="#myModal" data-toggle="modal" th:onclick="delete_file([[${file.toString()}]]);">删除</a>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>

            </div>

        </main>
        <!--End 页面主要内容-->
    </div>
</div>
<script th:inline="javascript">
    $(function(){
        /*<![CDATA[*/
        var msg = /*[[${msg}]]*/ null;
        /*]]>*/
        if(msg!=null){
            alert(msg);
        }
    })
    function download(filename) {
        /*<![CDATA[*/
        var context = /*[[${#httpServletRequest.getContextPath()}]]*/ null;
        /*]]>*/
        // window.location.href=context+"/file/download?filepath="+$("#filepath").val()+"&filename="+filename;
        post(context+"/file/download",{"filepath":$("#filepath").val(),"filename":filename});
    }
    function enter_path(path) {
        /*<![CDATA[*/
        var context = /*[[${#httpServletRequest.getContextPath()}]]*/ null;
        /*]]>*/
        post(context+"/file/filepath",{"path":path});
    }
    function delete_file(name) {
        $("#name").val(name);
    }
    function navigation_path(index) {
        /*<![CDATA[*/
        var context = /*[[${#httpServletRequest.getContextPath()}]]*/ null;
        /*]]>*/
        var path="";
        for(var i=1;i<=index;i++){
            path=path+"/"+$("#"+"navigation"+i).val();
        }
        post(context+"/file/filepath",{"path":path});
    }
    function post(URL, PARAMS) {
        var temp = document.createElement("form");
        temp.action = URL;
        temp.method = "post";
        temp.style.display = "none";
        for (var x in PARAMS) {
            var opt = document.createElement("textarea");
            opt.name = x;
            opt.value = PARAMS[x];
            // alert(opt.name)
            temp.appendChild(opt);
        }
        document.body.appendChild(temp);
        temp.submit();
        return temp;
    }
</script>
</body>
</html>